<html>
<head>
	<title>Debatepapo 2.0</title>
<?php
	require_once 'config.php';
	require_once 'php/Session.php';
	$session = new Session();

	if($session->isStarted()){
		
		header('Location: lobby.php');
	
	}else{ //session hasn't started yet
		require_once 'php/Communicator.php';
		$cmm = new Communicator();
		$userId = $cmm->getUserId();
		
		if($userId == 0){ //user id returned is 0, user is not logged in
			$url = $cmm->getLoginUrl();

?>		
		<meta charset="UTF-8" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<link rel="stylesheet" type="text/css" href="css/global.css">

		<style>

			#toolbar .menu button.signIn{
				font-size: 8pt;
				font-weight: bold;

				color: rgb(255,255,255);
				
				background: rgb(100,125,175);
				background: -moz-linear-gradient(bottom, rgb(90, 115, 165), rgb(100,125,175)) repeat-x;
    			background: -webkit-gradient(linear, left bottom, left top, from(rgb(90, 115, 165)), to(rgb(100,125,175)));

				padding: 4px 5px;
				border: 1px solid rgb(40,70,125);
				border-bottom-color: rgb(25,50,110);

				box-shadow: 0px 1px 2px rgba(0,0,0,.7);
			}

			.note{
				font-size: 8pt;
				color: rgb(255,255,255);
				float: left;
				margin-right: 10px;
				line-height: 38px;
			}

		</style>

	</head>
	<body>

		<section id='toolbar'>
			<div class='toolbarArea'>
				<div class='area'>
					<div class='menu'>
						<p class='note'>Você não está logado no sistema</p>
						<a href='<?php echo $url; ?>'><button class='signIn'>Entrar</button></a>
					</div>
				</div>
			</div>
		</section>

		<div id='content'>
			
		</div>
		
	</body>
<?php

		}else{
			require_once 'php/User.php';
			$user = new User($userId);

			$session->setUser($user);
			$session->start();

			header('Location: lobby.php');
		}
	}
?>
</html>